#define _CRT_SECURE_NO_WARNINGS 1
#include<vector>
#include<string>
#include<iostream>
using namespace std;

class Solution {
public:
    string longestPalindrome(string s) {
        //if(s.size()==1)return s;
        vector<string> vs;
        for (int i = 0; i < s.size(); i++)
        {
            string tmp;
            tmp += s[i];
            int left = i - 1, right = i + 1;
            while (left >= 0 && right <= s.size() - 1)
            {
                if (s[left] == s[right])
                {
                    tmp.insert(tmp.begin(), s[left]);
                    tmp.push_back(s[right]);
                    left--;
                    right++;
                }
                else break;
            }

            vs.push_back(tmp);

            tmp.clear();
            left = i, right = i + 1;
            while (left >= 0 && right <= s.size() - 1)
            {
                if (s[left] == s[right])
                {
                    tmp.insert(tmp.begin(), s[left]);
                    tmp.push_back(s[right]);
                    left--;
                    right++;
                }
                else break;
            }
            vs.push_back(tmp);
        }
        int max = 0;
        int ret = 0;
        for (int i = 0; i < vs.size(); i++)
        {
            if (vs[i].size() > max)
            {
                max = vs[i].size();
                ret = i;
            }
        }
        return vs[ret];

    }
};